ERROR = require './_error'
PG = require('fckoa/db/pg')

module.exports = {
    password : (password) ->
        password = password.trim()
        if password.length < 8 or password.length > 64
            err = ERROR.PASSWORD.LENGTH
        # else if password.toLowerCase() == password
        #     err = "密码必须包含大写字符"
        # else if password.toUpperCase() == password
        #     err = "密码必须包含小写字符"
        return err

    # antifish:(antifish)->
    #     antifish = antifish.trim()
    #     if antifish.length < 7
    #         err = "防钓鱼码最少7个字符"
    #     else if antifish.replace(/[^\x00-\xff]/g, "**").length > 64
    #         err = "防钓鱼码最多32个中文字符"
    #     return err

    name:(name, user_id)->
        name = name.trim()

        if name.length < 2 or name.length > 32
            err = ERROR.NAME.LENGTH
        else if /^\d+$/.test(name)
            err = ERROR.NAME.DIGIT
        else if not name.match(/^[^<>%$+\\/:*?"'|@&=#$]*$/)
            err = ERROR.NAME.FORMAT
            # _user_id = parseInt(yield PIKA.hget('name2id', name) or 0)
            # if _user_id and _user_id != user_id
            #    err = "该昵称已被使用（加数字后缀试试？）"

        return err
}
